package com.jianggujin.redis.panel.value;

import java.awt.BorderLayout;

import javax.swing.JPanel;

import com.jianggujin.redis.component.JEditorTable;
import com.jianggujin.redis.node.RedisKey;
import com.jianggujin.redis.panel.ValuePanel;

import redis.clients.jedis.Tuple;

public class ZSetValuePanel extends JPanel implements ValuePanel {
    private JEditorTable valueTable;

    public ZSetValuePanel() {
        super(new BorderLayout());
        valueTable = new JEditorTable(new String[] { "Score", "Element", "Action" });
        valueTable.setRowSelectionAllowed(false);
        add(valueTable);
    }

    @Override
    public void showValue(RedisKey redisKey) {
        valueTable.removeAllRow();
        for (Tuple item : redisKey.getClient().zrangeWithScores(redisKey.getKey(), 0, -1)) {
            valueTable.addRow(new Object[] { item.getScore(), item.getElement() });
        }
    }

}
